﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class admin_TourManager : System.Web.UI.Page
{
    public static int tourID;
    public static int hotelID;
    public static List<string> pathLinkAdd = new List<string>();
    public static List<ClassUnity.Images> pathLink = new List<ClassUnity.Images>();
    public static int mode;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!checkLoginAdmin())
            {
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('You have to login as Admin to access this page!');</script>");
                Response.Redirect("Login.aspx");
            }
            LoadData();
            ClearImage();

            //Sort
            if (GridView1.Rows.Count > 0)
            {
                GridView1.UseAccessibleHeader = true;
                GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
                //GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
            }
            else
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Have not tour!');</script>");
        }
    }
    // check login
    public bool checkLoginAdmin()
    {
        // check session
        if (Session["username"] != null)
        {
            return true;
        }
        else
        {
            // check cookie 
            if (Request.Cookies["username"] != null)
            {
                Session["username"] = Request.Cookies["username"].Value;
                Session["fullname"] = Request.Cookies["fullname"].Value;
                return true;
            }

        }
        return false;
    }
    private void LoadData()
    {
        DataTable dt = TourManagement.GetAllTour().Tables[0];
        GridView1.DataSource = dt;
        GridView1.DataBind();

        DataTable dtHotel = HotelManagement.GetAllHotel().Tables[0];
        ddlHotel.DataSource = ddlHotelEdit.DataSource = dtHotel;
        ddlHotel.DataTextField = ddlHotelEdit.DataTextField = HotelManagement.HOTELNAME;
        ddlHotel.DataValueField = ddlHotelEdit.DataValueField = HotelManagement.HOTELID;
        ddlHotel.DataBind();
        ddlHotelEdit.DataBind();

        MultiView1.ActiveViewIndex = 0;
    }


    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        LoadData();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        tourID = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());

        //Delete file img in server
        DataTable dtImageDel = ImageManagement.GetImgByForeignID(tourID, Common.IMAGE_TOUR).Tables[0];
        foreach (DataRow row in dtImageDel.Rows)
            File.Delete(Server.MapPath(row[ImageManagement.PATHLINK].ToString()));
        //Delete all image of tour have tourID= tourID
        ImageManagement.DeleteImg(Common.IMAGE_TOUR, tourID);
        //Delete TourHotel
        TourHotelManagement.DeleteTourHotelFromTour(tourID);
        //Delete OrderTour
        OrderTourManagement.DeleteOrderTourFromTour(tourID);
        //Delete tour
        if (TourManagement.DeleteTour(tourID))
            LoadData();
    }

    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        try
        {
            tourID = int.Parse(GridView1.DataKeys[e.NewSelectedIndex].Value.ToString());
            DataTable dtTour = TourManagement.GetTourByID(tourID);
            if (dtTour.Rows.Count > 0)
            {
                hiddenHotelID.Value = dtTour.Rows[0][HotelManagement.HOTELID].ToString();
                txtCodeEdit.Text = dtTour.Rows[0][TourManagement.TOURCODE].ToString();
                txtTourNameEdit.Text = dtTour.Rows[0][TourManagement.TOURNAME].ToString();
                txtRaceEdit.Text = dtTour.Rows[0][TourManagement.RACE].ToString();
                txtPlaceStartEdit.Text = dtTour.Rows[0][TourManagement.PLACESTART].ToString();
                txtPlaceEndEdit.Text = dtTour.Rows[0][TourManagement.PLACEEND].ToString();
                txtStartDateEdit.Text = DateTime.Parse(dtTour.Rows[0][TourManagement.STARTDATE].ToString()).ToShortDateString();
                txtEndDateEdit.Text = DateTime.Parse(dtTour.Rows[0][TourManagement.ENDDATE].ToString()).ToShortDateString();
                ddlIntervalTimeEdit.SelectedValue = dtTour.Rows[0][TourManagement.INTERVALTIME].ToString();
                //------Hotel's info---------
                ddlHotelEdit.SelectedValue = dtTour.Rows[0][HotelManagement.HOTELID].ToString();
                txtRoomEdit.Text = dtTour.Rows[0][TourHotelManagement.NUMROOM].ToString();
                txtDepartEdit.Text = DateTime.Parse(dtTour.Rows[0][TourHotelManagement.DEPARTDATE].ToString()).ToShortDateString();
                txtReturnEdit.Text = DateTime.Parse(dtTour.Rows[0][TourHotelManagement.RETURNDATE].ToString()).ToShortDateString();
                ddlNight.SelectedValue = dtTour.Rows[0]["night"].ToString();
                //------------End-------------
                txtPriceEdit.Text = String.Format("{0:0.##}", float.Parse(dtTour.Rows[0][TourManagement.PRICE].ToString()));
                txtSellPriceEdit.Text = String.Format("{0:0.##}", float.Parse(dtTour.Rows[0][TourManagement.SELLPRICE].ToString()));
                txtIteneraryEdit.Text = dtTour.Rows[0][TourManagement.ITINERARY].ToString();
                txtPlantEdit.Text = dtTour.Rows[0][TourManagement.PLANTOUR].ToString();
                if (dtTour.Rows[0][TourManagement.STATUS].ToString().Equals("True"))
                    txtStatusEdit.Text = "0";
                else
                    txtStatusEdit.Text = "1";
                LoadImage(tourID);
            }
        }
        catch (Exception ex) { }
        
        MultiView1.ActiveViewIndex = 2;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (txtSellPrice.Text.Equals(""))
            txtSellPrice.Text = txtPrice.Text;
        //Add Tour
        tourID = TourManagement.AddTour(txtCode.Text, txtTourName.Text, int.Parse(txtRace.Text), txtPlaceStart.Text,
            txtPlaceEnd.Text, DateTime.Parse(txtStartDate.Text), DateTime.Parse(txtEndDate.Text), float.Parse(ddlIntervalTime.SelectedValue),
            float.Parse(txtPrice.Text), float.Parse(txtSellPrice.Text), txtItenerary.Text, txtPlant.Text, txtStatus.Text == "1" ? false : true, pathLinkAdd);
        //Add Tour_Hotel
        if (tourID > -1 && !String.IsNullOrEmpty(ddlHotel.SelectedValue))
            TourHotelManagement.AddTourHotel(tourID, int.Parse(ddlHotel.SelectedValue), int.Parse(txtRoom.Text),
                DateTime.Parse(txtDepart.Text), DateTime.Parse(txtReturn.Text),float.Parse(ddlNightAdd.SelectedValue));

        LoadData();
        ClearImage();
        MultiView1.ActiveViewIndex = 0;
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        ClearImage();
        MultiView1.ActiveViewIndex = 0;
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < pathLink.Count; i++)
            ImageManagement.EditImg(pathLink[i].pathLink, pathLink[i].imageID);
        //add images for tour
        if (pathLinkAdd.Count > 0)
            for (int i = 0; i < pathLinkAdd.Count; i++)
                ImageManagement.AddImg(pathLinkAdd[i], Common.IMAGE_TOUR, tourID);
        //Edit Tour
        TourManagement.EditTour(tourID, txtCodeEdit.Text, txtTourNameEdit.Text, int.Parse(txtRaceEdit.Text), txtPlaceStartEdit.Text,
            txtPlaceEndEdit.Text, DateTime.Parse(txtStartDateEdit.Text), DateTime.Parse(txtEndDateEdit.Text), float.Parse(ddlIntervalTimeEdit.SelectedValue),
            float.Parse(txtPriceEdit.Text), float.Parse(txtSellPriceEdit.Text), txtIteneraryEdit.Text, txtPlantEdit.Text, txtStatusEdit.Text=="1"?false:true);
        //Edit Tour_Hotel
        TourHotelManagement.EditTourHotel(int.Parse(ddlHotelEdit.SelectedValue), int.Parse(txtRoomEdit.Text), DateTime.Parse(txtDepartEdit.Text),
                DateTime.Parse(txtReturnEdit.Text),float.Parse(ddlNight.SelectedValue), tourID, int.Parse(hiddenHotelID.Value));
        LoadData();
        ClearImage();
        MultiView1.ActiveViewIndex = 0;
    }
    protected void btnCancel2_Click(object sender, EventArgs e)
    {
        ClearImage();
        MultiView1.ActiveViewIndex = 0;
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Clear();
        MultiView1.ActiveViewIndex = 1;
    }

    public void Clear()
    {

    }
    //protected void btnShowStartDate_Click(object sender, EventArgs e)
    //{
    //    startDate.Visible = true;
    //}
    //protected void btnShowEndDate_Click(object sender, EventArgs e)
    //{
    //    endDate.Visible = true;
    //}
    //protected void startDate_SelectionChanged(object sender, EventArgs e)
    //{
    //    if (startDate.SelectedDate < DateTime.Now)
    //    {
    //        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Date start must greater now!');</script>"); 
    //        txtStartDate.Text = txtDepart.Text = DateTime.Now.ToShortDateString();
    //    }
    //    else
    //        txtStartDate.Text = txtDepart .Text = startDate.SelectedDate.ToShortDateString();
        
    //    startDate.Visible = false;
    //}
    //protected void endDate_SelectionChanged(object sender, EventArgs e)
    //{
    //    if (endDate.SelectedDate < startDate.SelectedDate)
    //    {
    //        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Date end must greater Date start!');</script>");
    //        txtEndDate.Text = txtReturn.Text = startDate.SelectedDate.ToShortDateString();
    //    }
    //    else
    //        txtEndDate.Text = txtReturn.Text = endDate.SelectedDate.ToShortDateString();
        
    //    endDate.Visible = false;
    //    ddlIntervalTime.SelectedValue = ddlNightAdd.SelectedValue = endDate.SelectedDate.Subtract(startDate.SelectedDate).Days.ToString();
    //}
    //protected void btnShowStartDateEdit_Click(object sender, EventArgs e)
    //{
    //    startDateEdit.Visible = true;
    //}
    //protected void btnShowEndDateEdit_Click(object sender, EventArgs e)
    //{
    //    endDateEdit.Visible = true;
    //}
    //protected void startDateEdit_SelectionChanged(object sender, EventArgs e)
    //{
    //    if (startDateEdit.SelectedDate<DateTime.Now)
    //        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Date start must greater now!');</script>");
    //    else
    //        txtStartDateEdit.Text = txtDepartEdit.Text = startDateEdit.SelectedDate.ToShortDateString();
    //    startDateEdit.Visible = false;
    //}
    //protected void endDateEdit_SelectionChanged(object sender, EventArgs e)
    //{
    //    if (endDateEdit.SelectedDate < DateTime.Parse(txtStartDateEdit.Text))
    //        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Date end must greater Date start!');</script>");
    //    else
    //        txtEndDateEdit.Text = txtReturnEdit.Text = endDateEdit.SelectedDate.ToShortDateString();
    //    endDateEdit.Visible = false;
    //    ddlIntervalTimeEdit.SelectedValue = endDateEdit.SelectedDate.Subtract(startDateEdit.SelectedDate).Days.ToString();
    //}
    protected void btnShowDepartDate_Click(object sender, EventArgs e)
    {
        //departDate.Visible = true;
    }
    protected void btnShowReturnDate_Click(object sender, EventArgs e)
    {
        //returnDate.Visible = true;
    }
    protected void departDate_SelectionChanged(object sender, EventArgs e)
    {
        //txtDepartDate.Text = departDate.SelectedDate.ToShortDateString();
        //departDate.Visible = false;
    }
    protected void returnDate_SelectionChanged(object sender, EventArgs e)
    {
        //txtReturnDate.Text = returnDate.SelectedDate.ToShortDateString();
        //returnDate.Visible = false;
    }
    protected void btnSearch_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            DateTime departDate = txtDepartDate.Text == "" ? DateTime.MinValue : DateTime.Parse(txtDepartDate.Text);
            DateTime returnDate = txtReturnDate.Text == "" ? DateTime.MinValue : DateTime.Parse(txtReturnDate.Text);

            DataTable dt = TourManagement.SearchTour(txtFrom.Text, txtTo.Text, departDate, returnDate).Tables["TourSearch"];
            GridView1.DataSource = dt;
            GridView1.DataBind();

        }
        catch (Exception ex) { }
        MultiView1.ActiveViewIndex = 0;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ImageUploadInsert();
    }
    protected void ButtonMore_Click(object sender, EventArgs e)
    {
        if (ButtonMore.Text == "Only five")
        {
            div2.Visible = false;
            ButtonMore.Text = "Add 10 Photos";
            div4.Visible = false;
        }

        else if (ButtonMore.Text == "Add 10 Photos")
        {
            div2.Visible = true;
            ButtonMore.Text = "Only five";
            div4.Visible = true;
        }
    }
    protected void btnUploadEdit_Click(object sender, EventArgs e)
    {
        ImageUploadEdit();
    }

    private void ClearImage()
    {
        Image1.ImageUrl = Image1Edit.ImageUrl =  "";
        Image2.ImageUrl = Image2Edit.ImageUrl =  "";
        Image3.ImageUrl = Image3Edit.ImageUrl =  "";
        Image4.ImageUrl = Image4Edit.ImageUrl =  "";
        Image5.ImageUrl = Image5Edit.ImageUrl =  "";
        Image6.ImageUrl = Image6Edit.ImageUrl =  "";
        Image7.ImageUrl = Image7Edit.ImageUrl =  "";
        Image8.ImageUrl = Image8Edit.ImageUrl =  "";
        Image9.ImageUrl = Image9Edit.ImageUrl =  "";
        Image10.ImageUrl = Image10Edit.ImageUrl =  "";
    }

    private void ImageUploadInsert()
    {
        div5.Visible = div5Edit.Visible = true;
        HttpFileCollection uploadFilCol = Request.Files;
        for (int i = 0; i < uploadFilCol.Count; i++)
        {
            HttpPostedFile file = uploadFilCol[i];
            string fileExt = Path.GetExtension(file.FileName).ToLower();
            string fileName = Path.GetFileName(file.FileName);
            if (fileName != string.Empty)
            {
                try
                {
                    if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
                    {
                        file.SaveAs(Server.MapPath("~/img/tours/") + fileName);
                        string linkImage = "~/img/tours/" + fileName;
                        pathLinkAdd.Add(linkImage);

                        if (i == 0)
                        {
                            Image1.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 1)
                        {
                            Image2.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 2)
                        {
                            Image3.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 3)
                        {
                            Image4.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 4)
                        {
                            Image5.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 5)
                        {
                            Image6.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 6)
                        {
                            Image7.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 7)
                        {
                            Image8.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 8)
                        {
                            Image9.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 9)
                        {
                            Image10.ImageUrl = linkImage;
                            continue;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
    }

    private void ImageUploadEdit()
    {
        div5.Visible = div5Edit.Visible = true;
        HttpFileCollection uploadFilCol = Request.Files;
        for (int i = 0; i < uploadFilCol.Count; i++)
        {
            HttpPostedFile file = uploadFilCol[i];
            string fileExt = Path.GetExtension(file.FileName).ToLower();
            string fileName = Path.GetFileName(file.FileName);
            if (fileName != string.Empty)
            {
                try
                {
                    if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
                    {
                        file.SaveAs(Server.MapPath("~/img/tours/") + fileName);
                        string linkImage = "~/img/tours/" + fileName;

                        if (i == 0)
                        {
                            if (Image1Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image1Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 1)
                        {
                            if (Image2Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image2Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 2)
                        {
                            if (Image3Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image3Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 3)
                        {
                            if (Image4Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image4Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 4)
                        {
                            if (Image5Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image5Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 5)
                        {
                            if (Image6Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image6Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 6)
                        {
                            if (Image7Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image7Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 7)
                        {
                            if (Image8Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image8Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 8)
                        {
                            if (Image9Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image9Edit.ImageUrl = linkImage;
                            continue;
                        }
                        if (i == 9)
                        {
                            if (Image10Edit.ImageUrl != "")
                            {
                                if (pathLink[i] != null)
                                    pathLink[i].pathLink = linkImage;
                            }
                            else
                                pathLinkAdd.Add(linkImage);
                            Image10Edit.ImageUrl = linkImage;
                            continue;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
    }

    private void LoadImage(int landID)
    {
        pathLink.Clear();
        pathLinkAdd.Clear();
        DataTable dtImageByLandID = ImageManagement.GetImgByForeignID(landID, Common.IMAGE_TOUR).Tables[0];
        for (int i = 0; i < dtImageByLandID.Rows.Count; i++)
        {
            ClassUnity.Images img = new ClassUnity.Images();
            img.imageID = int.Parse(dtImageByLandID.Rows[i][ImageManagement.IMAGEID].ToString());
            img.pathLink = dtImageByLandID.Rows[i][ImageManagement.PATHLINK].ToString();
            pathLink.Add(img);
        }

        //Fill pathLink into ...
        //FileUpload1Edit
        if (pathLink.Count > 5)
        {
            div2Edit.Visible = true;
            div4Edit.Visible = true;
        }
        else
        {
            div2Edit.Visible = false;
            div4Edit.Visible = false;
        }
        div5Edit.Visible = true;

        if (0 < pathLink.Count) if (pathLink[0] != null)
                Image1Edit.ImageUrl = pathLink[0].pathLink;
        if (1 < pathLink.Count) if (pathLink[1] != null)
                Image2Edit.ImageUrl = pathLink[1].pathLink;
        if (2 < pathLink.Count) if (pathLink[2] != null)
                Image3Edit.ImageUrl = pathLink[2].pathLink;
        if (3 < pathLink.Count) if (pathLink[3] != null)
                Image4Edit.ImageUrl = pathLink[3].pathLink;
        if (4 < pathLink.Count) if (pathLink[4] != null)
                Image5Edit.ImageUrl = pathLink[4].pathLink;
        if (5 < pathLink.Count) if (pathLink[5] != null)
                Image6Edit.ImageUrl = pathLink[5].pathLink;
        if (6 < pathLink.Count) if (pathLink[6] != null)
                Image7Edit.ImageUrl = pathLink[6].pathLink;
        if (7 < pathLink.Count) if (pathLink[7] != null)
                Image8Edit.ImageUrl = pathLink[7].pathLink;
        if (8 < pathLink.Count) if (pathLink[8] != null)
                Image9Edit.ImageUrl = pathLink[8].pathLink;
        if (9 < pathLink.Count) if (pathLink[9] != null)
                Image10Edit.ImageUrl = pathLink[9].pathLink;
    }
    protected void btnButtonMoreEdit_Click(object sender, EventArgs e)
    {
        if (btnButtonMoreEdit.Text == "Only five")
        {
            div2Edit.Visible = false;
            btnButtonMoreEdit.Text = "Add 10 Photos";
            div4Edit.Visible = false;
        }

        else if (btnButtonMoreEdit.Text == "Add 10 Photos")
        {
            div2Edit.Visible = true;
            btnButtonMoreEdit.Text = "Only five";
            div4Edit.Visible = true;
        }
    }
    protected void btnShowDepart_Click(object sender, EventArgs e)
    {
        //departDateEditCal.Visible = true;
    }
    //protected void departDateEditCal_SelectionChanged(object sender, EventArgs e)
    //{
    //    if (departDateEditCal.SelectedDate < DateTime.Parse(txtStartDateEdit.Text))
    //        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Depart must greater Date start!');</script>");
    //    else
    //        txtDepartEdit.Text = departDateEditCal.SelectedDate.ToShortDateString();

    //    departDateEditCal.Visible = false;
    //}
    //protected void btnShowReturnEdit_Click(object sender, EventArgs e)
    //{
    //    returnDateEditCal.Visible = true;
    //}
    //protected void returnDateEditCal_SelectionChanged(object sender, EventArgs e)
    //{
    //    //return < depart
    //    if (returnDateEditCal.SelectedDate < DateTime.Parse(txtDepartEdit.Text))
    //        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Return must greater depart!');</script>");
    //    else
    //    {
    //        //return > endDate
    //        if (returnDateEditCal.SelectedDate > DateTime.Parse(txtEndDateEdit.Text))
    //            ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Return must less than Date end!');</script>");
    //        else
    //            txtReturnEdit.Text = returnDateEditCal.SelectedDate.ToShortDateString();
    //        returnDateEditCal.Visible = false;
    //        ddlNight.SelectedValue = returnDateEditCal.SelectedDate.Subtract(departDateEditCal.SelectedDate).Days.ToString();
    //    } 
    //}
    //protected void btnShowDepart_Click1(object sender, EventArgs e)
    //{
    //    departDateCal.Visible = true;
    //}
    //protected void departDateCal_SelectionChanged(object sender, EventArgs e)
    //{
    //    if (departDateCal.SelectedDate < startDate.SelectedDate)
    //    {
    //        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Depart must greater Date start!');</script>");
    //        txtDepart.Text = startDate.SelectedDate.ToShortDateString();
    //    }
    //    else
    //        txtDepart.Text = departDateCal.SelectedDate.ToShortDateString();

    //    departDateCal.Visible = false;
    //}
    //protected void btnShowReturn_Click(object sender, EventArgs e)
    //{
    //    returnDateCal.Visible = true;
    //}
    //protected void returnDateCal_SelectionChanged(object sender, EventArgs e)
    //{
    //    //return < depart
    //    if (returnDateCal.SelectedDate < departDateCal.SelectedDate)
    //    {
    //        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Return must greater depart!');</script>");
    //        txtReturn.Text = departDateCal.SelectedDate.ToShortDateString();
    //    }
    //    else
    //    {
    //        //return > endDate
    //        if (returnDateCal.SelectedDate > endDate.SelectedDate)
    //        {
    //            ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Return must less than Date end!');</script>");
    //            txtReturn.Text = endDate.SelectedDate.ToShortDateString();
    //        }
    //        else
    //            txtReturn.Text = returnDateCal.SelectedDate.ToShortDateString();
    //        returnDateCal.Visible = false;
    //        ddlNightAdd.SelectedValue = returnDateCal.SelectedDate.Subtract(departDateCal.SelectedDate).Days.ToString();
    //    }
    //}
    protected void LinkButton6_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(ddlHotel.SelectedValue))
        {
            mode = Common.MODE_INSERT;
            hotelID = int.Parse(ddlHotel.SelectedValue);
            ShowDetailHotel(hotelID);
            MultiView1.ActiveViewIndex = 3;
        }
    }
    protected void LinkButton7_Click(object sender, EventArgs e)
    {
        mode = Common.MODE_EDIT;
        hotelID = int.Parse(ddlHotelEdit.SelectedValue);
        ShowDetailHotel(hotelID);
        MultiView1.ActiveViewIndex = 3;
    }

    private void ShowDetailHotel(int hotelID)
    {
        DataTable dtHotelByID =  HotelManagement.GetHotelByID(hotelID).Tables[0];

        lblHotelName.Text = dtHotelByID.Rows[0][HotelManagement.HOTELNAME].ToString();
        ddlStartHotel.SelectedValue = dtHotelByID.Rows[0][HotelManagement.START].ToString();
        lblPrice.Text = dtHotelByID.Rows[0][HotelManagement.PRICE].ToString();
        lblTel.Text = dtHotelByID.Rows[0][HotelManagement.PHONE].ToString();
        lblAddress.Text = dtHotelByID.Rows[0][HotelManagement.ADDRESS].ToString();
        lblDes.Text = dtHotelByID.Rows[0][HotelManagement.HOTELDESCRIPTION].ToString();

        DataTable dtImageByLandID = ImageManagement.GetImgByForeignID(hotelID, Common.IMAGE_HOTEL).Tables[0];
        List<string> pathLinkImg = new List<string>();
        for (int i = 0; i < dtImageByLandID.Rows.Count; i++)
            pathLinkImg.Add(dtImageByLandID.Rows[i][ImageManagement.PATHLINK].ToString());

        //Fill pathLinkImg into ...
        if (pathLinkImg.Count > 5)
            div4Edit0.Visible = true;
        else
            div4Edit0.Visible = false;
        //div5Edit0.Visible = true;

        if (0 < pathLinkImg.Count) if (pathLinkImg[0] != null)
                Image1Edit0.ImageUrl = Image1Edit0.FullImageURL = pathLinkImg[0].ToString();
        if (1 < pathLinkImg.Count) if (pathLinkImg[1] != null)
                Image2Edit0.ImageUrl = Image2Edit0.FullImageURL = pathLinkImg[1].ToString();
        if (2 < pathLinkImg.Count) if (pathLinkImg[2] != null)
                Image3Edit0.ImageUrl = Image3Edit0.FullImageURL = pathLinkImg[2].ToString();
        if (3 < pathLinkImg.Count) if (pathLinkImg[3] != null)
                Image4Edit0.ImageUrl = Image4Edit0.FullImageURL = pathLinkImg[3].ToString();
        if (4 < pathLinkImg.Count) if (pathLinkImg[4] != null)
                Image5Edit0.ImageUrl = Image5Edit0.FullImageURL = pathLinkImg[4].ToString();
        if (5 < pathLinkImg.Count) if (pathLinkImg[5] != null)
                Image6Edit0.ImageUrl = Image6Edit0.FullImageURL = pathLinkImg[5].ToString();
        if (6 < pathLinkImg.Count) if (pathLinkImg[6] != null)
                Image7Edit0.ImageUrl = Image7Edit0.FullImageURL = pathLinkImg[6].ToString();
        if (7 < pathLinkImg.Count) if (pathLinkImg[7] != null)
                Image8Edit0.ImageUrl = Image8Edit0.FullImageURL = pathLinkImg[7].ToString();
        if (8 < pathLinkImg.Count) if (pathLinkImg[8] != null)
                Image9Edit0.ImageUrl = Image9Edit0.FullImageURL = pathLinkImg[8].ToString();
        if (9 < pathLinkImg.Count) if (pathLinkImg[9] != null)
                Image10Edit0.ImageUrl = Image10Edit0.FullImageURL = pathLinkImg[9].ToString();
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        ClearImageHotelDetail();

        if (mode == Common.MODE_INSERT)
            MultiView1.ActiveViewIndex = 1;
        if(mode == Common.MODE_EDIT)
            MultiView1.ActiveViewIndex = 2;
    }

    private void ClearImageHotelDetail()
    {
        Image1Edit0.ImageUrl = "";
        Image2Edit0.ImageUrl = "";
        Image3Edit0.ImageUrl = "";
        Image4Edit0.ImageUrl = "";
        Image5Edit0.ImageUrl = "";
        Image6Edit0.ImageUrl = "";
        Image7Edit0.ImageUrl = "";
        Image8Edit0.ImageUrl = "";
        Image9Edit0.ImageUrl = "";
        Image10Edit0.ImageUrl = "";
    }
    protected void txtStartDate_TextChanged(object sender, EventArgs e)
    {
        try
        {
            if (DateTime.Parse(txtStartDate.Text) < DateTime.Now)
            {
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Date start must greater now!');</script>");
                txtStartDate.Text = txtDepart.Text = DateTime.Now.ToShortDateString();
            }
            else
                txtDepart.Text = txtStartDate.Text;
        }
        catch (Exception ex) { }
    }
    protected void txtEndDate_TextChanged(object sender, EventArgs e)
    {
        try
        {
            if (DateTime.Parse(txtEndDate.Text) < DateTime.Parse(txtStartDate.Text))
            {
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Date end must greater Date start!');</script>");
                txtEndDate.Text = txtReturn.Text = txtStartDate.Text;
            }
            else
                txtReturn.Text = txtEndDate.Text;

            ddlIntervalTime.SelectedValue = ddlNightAdd.SelectedValue = DateTime.Parse(txtEndDate.Text).Subtract( DateTime.Parse(txtStartDate.Text)).Days.ToString();
        }
        catch (Exception ex) { }
    }
    protected void  txtDepart_TextChanged(object sender, EventArgs e)
    {
        try
        {
            if (DateTime.Parse(txtDepart.Text) < DateTime.Parse(txtStartDate.Text))
            {
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Depart must greater Date start!');</script>");
                txtDepart.Text = txtStartDate.Text;
            }
        }
        catch (Exception ex) { }
    }
    protected void  txtReturn_TextChanged(object sender, EventArgs e)
    {
        try
        {
            //return < depart
            if (DateTime.Parse(txtReturn.Text) < DateTime.Parse(txtDepart.Text))
            {
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Return must greater depart!');</script>");
                txtReturn.Text = txtDepart.Text;
            }
            else
            {
                //return > endDate
                if (DateTime.Parse(txtReturn.Text) > DateTime.Parse(txtEndDate.Text))
                {
                    ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Return must less than Date end!');</script>");
                    txtReturn.Text = txtEndDate.Text;
                }

                ddlNightAdd.SelectedValue = DateTime.Parse(txtReturn.Text).Subtract(DateTime.Parse(txtDepart.Text)).Days.ToString();
            }
        }
        catch (Exception ex) { }
    }
    protected void txtStartDateEdit_TextChanged(object sender, EventArgs e)
    {
        try
        {
            if (DateTime.Parse(txtStartDateEdit.Text) < DateTime.Now)
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Date start must greater now!');</script>");
            else
                txtDepartEdit.Text = txtStartDateEdit.Text;
        }
        catch (Exception ex) { }
    }
    protected void txtEndDateEdit_TextChanged(object sender, EventArgs e)
    {
        try
        {
            if (DateTime.Parse(txtEndDateEdit.Text) < DateTime.Parse(txtStartDateEdit.Text))
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Date end must greater Date start!');</script>");
            else
                txtReturnEdit.Text = txtEndDateEdit.Text;

            ddlIntervalTimeEdit.SelectedValue = DateTime.Parse(txtEndDateEdit.Text).Subtract(DateTime.Parse(txtStartDateEdit.Text)).Days.ToString();
        }
        catch (Exception ex) { }
    }
    protected void txtDepartEdit_TextChanged(object sender, EventArgs e)
    {
        try
        {
            if (DateTime.Parse(txtDepartEdit.Text) < DateTime.Parse(txtStartDateEdit.Text))
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Depart must greater Date start!');</script>");
        }
        catch (Exception ex) { }
    }
    protected void txtReturnEdit_TextChanged(object sender, EventArgs e)
    {
        try
        {
            //returnDateEditCal_SelectionChanged
            //return < depart
            if (DateTime.Parse(txtReturnEdit.Text) < DateTime.Parse(txtDepartEdit.Text))
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Return must greater depart!');</script>");
            else
            {
                //return > endDate
                if (DateTime.Parse(txtReturnEdit.Text) > DateTime.Parse(txtEndDateEdit.Text))
                    ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Return must less than Date end!');</script>");

                ddlNight.SelectedValue = DateTime.Parse(txtReturnEdit.Text).Subtract(DateTime.Parse(txtDepartEdit.Text)).Days.ToString();
            }
        }
        catch (Exception ex) { }
    }
}